package cn.dujc.superkid.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import cn.dujc.core.ui.BaseActivity;
import cn.dujc.superkid.R;
import cn.dujc.superkid.bean.RegisterResult;
import cn.dujc.superkid.utils.Preferences;

/**
 * @author du
 * date 2018/8/2 上午12:39
 */
public class SettingActivity extends BaseActivity implements View.OnClickListener{
    private LinearLayout resetPwd;
    private RegisterResult registerResult;
    private LinearLayout vipMsg;
    private LinearLayout records;
    private LinearLayout service;
    private TextView quit;
    @Override
    public int getViewId() {
        return R.layout.activity_setting;
    }

    @Override
    public void initBasic(Bundle savedInstanceState) {
//        if (!Preferences.isLogin(this)) {
//                    starter().go(MainActivity.class);
//                    finish();
//                }
        setTitle("设置");
        initView();
    }

    private void initView() {
        resetPwd = findViewById(R.id.resetPwd);
        vipMsg = findViewById(R.id.vip_meaasge);
        records = findViewById(R.id.records);
        service = findViewById(R.id.service);
        quit = findViewById(R.id.quit);
        quit.setOnClickListener(this);
        resetPwd.setOnClickListener(this);
        vipMsg.setOnClickListener(this);
        records.setOnClickListener(this);
        service.setOnClickListener(this);
        findViewById(R.id.service).setOnClickListener(this);
        findViewById(R.id.records).setOnClickListener(this);
        if (!Preferences.isLogin(this)) {
            quit.setText("注册|登录");
        }else {
            quit.setText("退出登录");
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.resetPwd:
                Intent intent = new Intent(SettingActivity.this,ResetPwdActivity.class);
                startActivity(intent);
//                startActivity(new Intent(SettingActivity.this,ResetPwdActivity.class));
                break;
            case R.id.vip_meaasge:
                startActivity(new Intent(SettingActivity.this,VipActivity.class));
                break;
            case R.id.quit:
                if (!Preferences.isLogin(this)) {
                    quit.setText("注册|登录");
                }else {
                    Preferences.getInstance().saveLoginResult(mActivity, registerResult);
                    setResult(RESULT_OK);
                    Intent logoutIntent = new Intent(SettingActivity.this, LoginActivity.class);
                    startActivity(logoutIntent);
                }
                finish();
                break;
            case R.id.service:
                startActivity(new Intent(this,ServiceActivity.class));
                break;
            case R.id.records:
                startActivity(new Intent(this,ActivityRecords.class));
                break;
        }
    }
}
